<template>
	<view class="box">
		<view class="header">
			<u--text size="18" :text="movie.movieName"></u--text>
			<div style="font-size: 14px;">
				<p style="color: forestgreen;">{{movie.playDate}}-{{movie.startTime}}</p>
				<p>{{movie.theatreName}}--{{movie.roomName}}</p>
				<div class="tags">
					<u-tag :text="item" size="size" type="info" plain v-for="(item,index) in seat"></u-tag>
				</div>
			</div>
		</view>
		<view class="price">
			<div>
				<span>票价</span>
				<span style="float: right;margin-right: 20rpx;font-size: 24rpx;">含服务费3元/张 <span style="color: #2a9d26; font-size: 28rpx;">{{(movie.price+3)*seat.length}}元</span></span>
			</div>
		</view>
		<view class="btn">
			<span style="float: right;padding: 20rpx;font-size: 24rpx;">还需支付 <span style="color: #2a9d26; font-size: 28rpx;">{{(movie.price+3)*seat.length}}元</span></span>
			<u-button text="支付" type="success" @click="submit"></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				seat:[],
				seatId:0,
				movie:{}
			};
		},
		onLoad(opt) {
			this.seat=JSON.parse(opt.seat)
			this.movie=JSON.parse(opt.movie)
			this.seatId=JSON.parse(opt.seatId)
			console.log(this.movie);
		},
		methods:{
			submit(){
					this.seatId.forEach(item=>{//发送购票请求
						this.$request({
							url: '/prod-api/api/movie/ticket',
							method: 'POST',
							data:{
								movieId:this.movie.movieId,
								price:this.movie.price,
								seatId:item,
								roomId:this.movie.roomId,
								theaterId:this.movie.theaterId,
								timesId:this.movie.id
							}
							
						}).then(res => {
							if(res.data.code=="200"){
								console.log(res);
							}else if(res.data.code="401"){
								uni.$u.toast("你还没有登录呢！！！")
								setTimeout(()=>{
									uni.navigateTo({
										url:'/pages/login/login'
									})
								},500)
							}
							
						}).catch(err => {
							console.log(err,'err啊');
						})
					})
					setTimeout(()=>{
						uni.navigateTo({
								url:'/pages/myOrders/myOrders'
						})
					},300)
			}
		}
	}
</script>

<style lang="scss" scoped>
.box{
	background-color: #ececec;
	height: 100vh;
	.header{
		padding: 20rpx 15rpx;
		background-color: white;
		.tags{
			// height: 120rpx;
			.u-transition{
				width: 140rpx;
				
				display: inline-block;
				margin: 10rpx 5rpx;
				/deep/.u-tag{
					justify-content: center;
					
				}
			}
		}
	}
	.price{
		border-top: 1px solid #ececec;
		background-color: white;
		height: 60rpx;
		line-height: 60rpx;
		padding: 0rpx 15rpx;
	}
	.btn{
		margin-top: 20rpx;

		background-color: white;
	}
}
</style>
